package com.zto.sch.advance.caffeine;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

/**
 * @program: sch-diy-parent
 * @description:基于缓存容量大小驱逐缓存
 * @author: sch
 * @create: 2020-12-25 21:55
 **/
public class CaffeineDemoExpel1 {
    public static void main(String[] args) {
        Cache<String, String> cache = Caffeine.newBuilder().maximumSize(5)
                .removalListener((k, v, r) -> {
                    System.out.println("移除: key = " + k + "，cause = " + r);
                }).build();
        for (int i = 0; i < 9; i++) {
            cache.put(String.valueOf(i), "小强" + i);
        }
        cache.cleanUp();
    }
}
